package JavaUtils.web.req.io;

import JavaUtils.CSUtils.CFile;
import JavaUtils.CSUtils.CString;
import JavaUtils.web.IWebCallback;
import JavaUtils.web.ReqInfo;
import com.alibaba.fastjson.JSON;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

public class Req_directory {
    public static IWebCallback GetFiles() {
        IWebCallback Directory_GetFiles = new IWebCallback() {
            @Override
            public void MsgHandle(ReqInfo reqInfo) throws IOException {
                String _dir = reqInfo.dataMap.get("dir");
                String midDir = reqInfo.dataMap.get("midDir");
                String ignoreDir = reqInfo.dataMap.get("ignoreDir");
                String suffixArr = reqInfo.dataMap.get("suffixArr");
                byte isTop = Byte.parseByte(reqInfo.dataMap.get("isTop"));
                String[] _midDirArr = midDir.split("\\|");
                String[] _ignoreDirArr = ignoreDir.split("\\|");
                String[] _suffixArr = suffixArr.split("\\|");
                List<String> filePathList = CFile.getFiles(_dir, _midDirArr, _ignoreDirArr, _suffixArr, isTop, null);

                CFile.RemoveFileListHead(_dir, filePathList);
                CString.sort_StrList(filePathList);

                String dfStr = CFile.FileListToDfStr(filePathList);
                reqInfo.resp_txt = dfStr;

                //if (false) {
                CFile.WriteAllLine("/Users/mac/Desktop/test_js/txt01.txt", filePathList);
                List<String> filePathList3 = CFile.DfStrToFileList(dfStr);
                CString.sort_StrList(filePathList3);
                CFile.WriteAllLine("/Users/mac/Desktop/test_js/txt02.txt", filePathList3);
                Object json = JSON.toJSON(filePathList);
                // }
            }
        };
        return Directory_GetFiles;
    }


    public static void Test_002() {
        Map<String, IWebCallback> eventMap = new HashMap<>();
        ReqInfo reqInfo = new ReqInfo();
        reqInfo.dataMap.put("dir", "/Users/mac/work/gitxia9000/unity3d/U3d_Packages/Assets");
        reqInfo.dataMap.put("midDir", "/ResourcesAB/txtData");
        reqInfo.dataMap.put("ignoreDir", "/.");
        reqInfo.dataMap.put("suffixArr", ".txt|.jpeg");
        reqInfo.dataMap.put("isTop", "0");
        try {
            GetFiles().MsgHandle(reqInfo);
        } catch (IOException ignored) {

        }
    }
}
